package com.gitee.yangtianle.redisson.seckill.spring.boot.autoautoconfigure.config;

import com.google.common.util.concurrent.RateLimiter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author tianle.ytl
 * @date 2018/9/19
 */
@Configuration
@ConditionalOnWebApplication
public class RateLimiterAutoConfiguration {

    /**
     * 默认每秒200次请求
     */
    private final static double DEFAULT_PERMITSPERSECOND = 200d;

    @Bean
    public RateLimiter initRateLimiter() {
        return RateLimiter.create(DEFAULT_PERMITSPERSECOND);
    }
}
